//
//  SWHomeModel.swift
//  SinaWeibo
//
//  Created by wszyxc on 16/7/23.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

import UIKit

class SWHomeModel: NSObject {
    
    /// 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    //  用户数据
    var user: SWUserModel?
    //  转发微博
    var retweeted_status:SWHomeModel?
    
    //图片数组
    var pic_urls:[SWPictureModel]?
    
    //转发数
    var reposts_count:Int = 0
    
    //评论
    var comments_count:Int = 0
    
    //赞
    var attitudes_count:Int = 0
    
    
    
    //KVC  构造函数
    
    init(dict:[String:AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user"{
            //判断value是否为nil,能否转化为字典
            
            guard let v = value as? [String:AnyObject] else{
                
                return
            }
            
            user = SWUserModel(dict: v)
            
        }else if key == "retweeted_status"{
            
            
            guard let v = value as? [String:AnyObject] else{
     
                return
            }
            
            retweeted_status = SWHomeModel(dict: v)
            
        }else if key == "pic_urls"{
           
            guard let v = value as? [[String: AnyObject]] else{
                
                return
            }
            
            var tempArr = [SWPictureModel]()
            
            for dic in v{
                
                let model:SWPictureModel = SWPictureModel(dict: dic)
                
                tempArr.append(model)
                
            }
            
            pic_urls = tempArr
            
            
        }else{
            
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
            
    }
    
    

}
